<?php 
	$this->headLink()->appendStylesheet( $this->baseUrl() . '/public/css/jquery.autocomplete.css' );
	$this->headScript()->appendFile( $this->baseUrl() . '/public/js/jquery.autocomplete.pack.js' );

	echo $this->inlineScript()->setScript('$(document).ready(function(){
		$("#from").datepicker({ dateFormat: "yy-mm-dd" });
		$("#to").datepicker({ dateFormat: "yy-mm-dd" });
		
		function format(row) {
			return row.to;
		}
		var res;
		$("#suggest").autocomplete("' . $this->baseUrl() . '/cporders/find", {
			multiple: false,
			dataType: "json",
			parse: function(data) {
				return $.map(data, function(row) {
					return {
						data: row,
						value: row.id,
						result: row.to
					}
				});
			},
			formatItem: function(item) {
				return format(item);
			}
		}).result(function(e, item) {
			$("#o_id").val( item.id );
		});
	})'); 

?>

<div class="bglist">
	<div class="bglistq">
		<form id="formrap" method="get">
			<input type="hidden" id="excel" name="excel" value="0" />
			<table cellspacing="1" cellpadding="4" class="tlist">
				<tr>
					<th style="font-size:11px;">Zapłacone</th>
					<th style="font-size:11px;">Potwierdzone</th>
					<th style="font-size:11px;">Przygotowany</th>
					<th style="font-size:11px;">Wysłane</th>
					<th style="font-size:11px;">Zrealizowane</th>
					<th style="font-size:11px;">Województwo</th>
					<th style="font-size:11px;">Użytkownik</th>
					<th style="font-size:11px;">Od</th>
					<th style="font-size:11px;">Do</th>
					<th style="font-size:11px;" colspan="3">Filtruj</th>
				</tr>
				<tr>
					<td><?php echo $this->formSelect( 'state', ( $this->state > -1 && $this->state < 2  ) ? $this->state : 2, null, array( 'Nie', 'Tak', '--' ) ) ?></td>
					<td><?php echo $this->formSelect( 'state2', ( $this->state2 > -1 && $this->state2 < 2  ) ? $this->state2 : 2, null, array( 'Nie', 'Tak', '--' ) ) ?></td>
					<td><?php echo $this->formSelect( 'state3', ( $this->state3 > -1 && $this->state3 < 2  ) ? $this->state3 : 2, null, array( 'Nie', 'Tak', '--' ) ) ?></td>
					<td><?php echo $this->formSelect( 'state4', ( $this->state4 > -1 && $this->state4 < 2  ) ? $this->state4 : 2, null, array( 'Nie', 'Tak', '--' ) ) ?></td>
					<td><?php echo $this->formSelect( 'state5', ( $this->state5 > -1 && $this->state5 < 2  ) ? $this->state5 : 2, null, array( 'Nie', 'Tak', '--' ) ) ?></td>
					<td><?php echo $this->formSelect( 'province', ( $this->province > -1 && $this->province < 16  ) ? $this->province : 16, array(
						'style' => 'width: 80px'
					), Core_Static::$province2 ) ?></td>
					<td>
						<?php echo $this->formHidden( 'o_id', $this->users_u_id ) ?>
						<?php echo $this->formText( 'suggest', $this->user ); ?>
						<div id="suggest"></div>
					</td>
					<td><?php echo $this->formText( 'from', $this->from, array(
						'style' => 'width: 70px'
					) ); ?></td>
					<td><?php echo $this->formText( 'to', $this->to, array(
						'style' => 'width: 70px'
					) ); ?></td>
					<td>
						<a onclick="$('#formrap').find('#excel').val( 0 );$('#formrap').submit()" class="button" href="javascript::void(null)">
							<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/save_16.png);" class="inb">OK</div>
						</a>
					</td>
					<td>
						<a onclick="$('#formrap').find('#excel').val( 1 );$('#formrap').submit()" class="button" href="javascript::void(null)">
							<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/gear_16.png);" class="inb">CSV</div>
						</a>
					</td>
					<td>
						<a class="button" href="<?php echo $this->baseUrl() ?>/cporders">
							<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/up_16.png);" class="inb">CLEAR</div>
						</a>
					</td>
				</tr>
			</table>
		</form>
		
		<table cellspacing="1" cellpadding="6" class="tlist">
			<tr>
				<th>Numer</th>
				<th>Kwota</th>
				<th>Zapłacone</th>
				<th>Potwierdzone</th>
				<th>Przygotowne</th>
				<th>Wysłane</th>
				<th>Zrealizowane</th>
				<th>Data dodania</th>
				<th>Dane do wysyłki</th>
				<th>Dane do faktury</th>
				<th>Akcje</th>
			</tr>
			<?php foreach( $this->list as $item ) { ?>
			<tr>
				<td><?php echo $item['o_id'] ?></td>
				<td><?php echo $item['price'] . ' ' . $item['currency'] ?></td>
				<td><?php echo ( $item['state'] ) ? 'Tak' : 'Nie'; ?></td>
				<td><?php echo ( $item['state2'] ) ? 'Tak' : 'Nie'; ?></td>
				<td><?php echo ( $item['state3'] ) ? 'Tak' : 'Nie'; ?></td>
				<td><?php echo ( $item['state4'] ) ? 'Tak' : 'Nie'; ?></td>
				<td><?php echo ( $item['state5'] ) ? 'Tak' : 'Nie'; ?></td>
				<td><?php echo $item['add_date'] ?></td>
				<td>
					<?php if($item['vouchers_v_id']==0){ ?>
					<div class="sh" onclick="sh('#ashow<?php echo $item['o_id'] ?>')" >Pokaż / ukryj</div>
					<div id="ashow<?php echo $item['o_id'] ?>" style="display:none; margin-top:5px; font-size:10px">
					<?php 
					    echo $item['name_to_dispatch'].' '.$item['surname_to_dispatch'].'<br>';
					    echo $item['street_to_dispatch'].' '.$item['nr_home_to_dispatch'].' '.$item['nr_flat_to_dispatch'].'<br>';
					    echo $item['zip_to_dispatch'].' '.$item['locality_to_dispatch'].'<br>';
					    echo $this->arrayprovince[$item['province_to_dispatch']].'<br>';
					    echo $this->arraycountry[$item['country_to_dispatch']].'<br>';
					?>
					</div>
					<?php } else {?>
					<span style="color:#a2a2a2;" title="Zamówiono bon podarunkowy">nie dotyczy</span>
					<?php } ?>
				</td>
				<td>
					<div class="sh" onclick="sh('#bshow<?php echo $item['o_id'] ?>')" >Pokaż / ukryj</div>
					<div id="bshow<?php echo $item['o_id'] ?>" style="display:none; margin-top:5px; font-size:10px">
					<?php 
					    if(!empty($item['company_to_fv'])) echo $item['company_to_fv'].'<br>';
					    if(!empty($item['nip_to_fv'])) echo 'NIP:'.$item['nip_to_fv'].'<br>';
					    echo $item['name_to_fv'].' '.$item['surname_to_fv'].'<br>';
					    echo $item['street_to_fv'].' '.$item['nr_home_to_fv'].' '.$item['nr_flat_to_fv'].'<br>';
					    echo $item['zip_to_fv'].' '.$item['locality_to_fv'].'<br>';
					    echo $this->arrayprovince[$item['province_to_fv']].'<br>';
					    echo $this->arraycountry[$item['country_to_fv']].'<br>';
					?>
					</div>
				</td>
			
				<td>
					<a href="<?php echo $this->baseUrl() ?>/cporders/item/id/<?php echo $item['o_id'] ?>" class="edit">Szczegóły</a>
				</td>
			</tr>
			<?php } ?>
		</table>
	</div>
</div>

<script type="text/javascript">

	function sh(com)
	{
		$(com).toggle();
	}

	$(document).ready(function(){

		$('.sh').css('cursor','pointer');
		
	});
	

</script>

<?php  echo $this->render('global/pager.phtml'); ?>